//
// originalview.h
//
// The header file for original view of the input images
//

#ifndef ORIGINALVIEW_H
#define ORIGINALVIEW_H

#include <FL/Fl.H>

#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
#include <GL/gl.h>
#include <GL/glu.h>

#include <stdlib.h>
#include "Point.h"

typedef enum {kNone,kX,kY,kZ,kCalAxis,kPoint,kFifthPoint, kMovePoint,kVertical,kConnect} uiState;
typedef enum {RED,GREEN,BLUE,YELLOW} kColor;

class Impressionist;

class OriginalView : public Fl_Gl_Window
{
public:
	OriginalView(int x, int y, int w, int h, const char *l);
	
	void draw();
	virtual int handle(int event); 
	void refresh();

	void resizeWindow(int width, int height);

	Impressionist*	m_pDoc;
	uiState		m_state;	//UI state
	vector<pair<Point,Point>>	m_axis[3];		//parallel lines
	vector<Point>	m_points;	//array for reference plane points (in total 4) in drawing space
	Point			m_zin,m_zout;		// the out of plane point in drawing space, zin is the normal in plane
	vector<Point>			m_rootpts;		//these two arrays are indeed pairs, just because using pair is tedious
	vector<Point>			m_spacepts;
	vector<Point>			m_patch;		//holder for current patch (4 elements at most)
	vector<int>			m_vrml;		//all faces

	Point GetScrollPosition();
	void drawPoint(Point pt);
	void drawPoint(Point pt, int c);	//with color
	void drawPoint(Point pt, int c, int size);	//with color and point size
	void drawLine(Point pt1, Point pt2, int c);		//two points and a color

	void calAxis ();	//move data to impressionist.h and calculate vanishing point
	void calHomo ();		//move data to impressionist.h and calculate homography
	void calPatch ();		//move data to impressionist.h 
	void exportPatch ();		//calculate patch and gen VRML
	void resetPatch();
	void resetAxis ();		//clean up axis info
	void resetGlobals();	//clean up globals for drawing
	void resetPoints();

private:
	int	m_nWindowWidth, 
		m_nWindowHeight;
	
	void setLinePt(Point pt, int axisID);
	bool withinRadius(Point x, Point y);		//return true if x,y distance is within radius
	string printCoord (Point pt);	//return point coordinate in (x,y) format
};

#endif